package com.dynamic.data.permission.interceptor;

import com.dynamic.data.permission.model.ResourceCheckHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class ResourceCheckAspect {

    // 定义切点，匹配带有 CustomAnnotation 注解的方法
    @Pointcut("@annotation(com.dynamic.data.permission.annotation.ResourceCheck)")
    public void annotationPointcut() {
    }

    // 在目标方法执行前执行
    @Before("annotationPointcut()")
    public void beforeAdvice(JoinPoint joinPoint) {
        ResourceCheckHolder.set(true);
    }

    // 在目标方法执行后执行
    @After("annotationPointcut()")
    public void afterAdvice(JoinPoint joinPoint) {
        ResourceCheckHolder.clear();
    }
}
